package com.cykj.common.utils;


import jakarta.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.common.utils
 * @Author: 蔡张君逸
 * @CreateTime: 2025-08-28 21:35
 * @Description: 邮箱验证工具类
 * @Version: 1.0
 */
@Component
public class EmailValidateUtil {
    @Value("${spring.mail.username}")
    private String from;
    @Autowired
    JavaMailSender mailSender;
    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    public void send(String to,String msg,String title) throws Exception {

        // 创建一个邮件消息
        MimeMessage message = mailSender.createMimeMessage();

        // 创建 MimeMessageHelper
        MimeMessageHelper helper = new MimeMessageHelper(message, false);

        // 发件人邮箱和显示名称
        helper.setFrom(from, "智慧招聘系统");
        // 收件人邮箱
        helper.setTo(to);
        // 邮件标题
        helper.setSubject(title);
        // 邮件正文，第二个参数表示是否是HTML正文
        helper.setText(msg, false);

        // 发送
        mailSender.send(message);
    }
}